class BSTnode:
	def __init__(self, val):
		self.val = val  # 数据
		self.left = None  # 左节点
		self.right = None  # 右节点
		self.parent = None  # 父节点


class BST(object):
	def __init__(self):
		self.root = None  # 根节点

	def insert(self, val):
		'''添加'''
		newNode = BSTnode(val)
		if self.root is None:
			self.root = newNode
		
		else:
			curNode = self.root

			while True:
				if val < curNode.val:
					if curNode.left is None:
						curNode.left = newNode
						newNode.parent = newNode
						break
					curNode = curNode.left

				else:
					if curNode.right is None:
						curNode.right = newNode
						newNode.parent = newNode
						break
					curNode = curNode.right

	def find(self, val):
		curNode = self.root

		while curNode is not None:
			if val < curNode.val:
				curNode = curNode.left

			elif val > curNode.val:
				curNode = curNode.right

			else:
				return True

		return False

mylist = [2,5,4,7,8,4,2,3]
bst = BST()
for i in mylist:
	bst.insert(i)


print(bst.find(8))